package com.wuzuqing.android.eightdiagrams.model

import android.annotation.SuppressLint
import com.wuzuqing.android.eightdiagrams.term.Bazhi
import com.wuzuqing.android.eightdiagrams.term.Bazhi.getNianGanShenSha
import com.wuzuqing.android.eightdiagrams.term.Bazhi.getNianZhiOther
import com.wuzuqing.android.eightdiagrams.term.Bazhi.getNianZhiShen
import com.wuzuqing.android.eightdiagrams.term.Bazhi.getRiGanShenSha
import com.wuzuqing.android.eightdiagrams.term.Bazhi.getRiZhiShenSha
import com.wuzuqing.android.eightdiagrams.term.Bazhi.getYueZhiShenSha
import com.wuzuqing.android.eightdiagrams.term.EightChar
import com.wuzuqing.android.eightdiagrams.term.Lunar
import com.wuzuqing.android.eightdiagrams.utils.Birth
import com.wuzuqing.android.eightdiagrams.utils.DataUtils
import com.wuzuqing.android.eightdiagrams.utils.DataUtils.CoinType
import java.text.SimpleDateFormat
import java.util.*
import kotlin.math.max

/**
 * @CopyRight: 广州仰望星空云科技有限公司
 * @Author : wuzuqing
 * @Email:wuzuqing@xinyu668.com
 * @CreateTime: 11.12.23 1:14 PM
 * @Description: 请写描述
 */
class BaZiInfo {

    fun buildTitle(): String {
        val text = StringBuilder()
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm")
        text.append("阳历:").append(sdf.format(time))
            .append("\n")
        text.append("真太阳时:").append(sdf.format(sumTime))
            .append("\n")
        text.append("农历:")
            .append(lunarDate?.year).append("年")
            .append(lunarDate?.month).append("月")
            .append(lunarDate?.day).append("日")
            .append("\n")
            .append("得分:").append(coin).append(";").append(if (coin > 50) "身强" else "身弱")
            .append("传统得分:").append(coinType.name)
            .append("   喜用神:").append(xiYongShen)
        text.append("   生肖:").append(animalsYear).append("\n")
        val list = DataUtils.getShiErShen1(shiGanInfo?.name.orEmpty())
        list?.also {
            val lucyNum =
                arrayListOf(DataUtils.getLucyNum(it[2]), DataUtils.getLucyNum(it[3]), DataUtils.getLucyNum(it[4]))
            text.append("幸运数字:").append(lucyNum.toString()).append("   ")
        } ?: also {

        }
        text.append("八字:")
        return text.toString()
    }

    private fun appendGz(info: BaseInfo?, arr: MutableList<String>) {
        info?.also {
            arr.add(it.name.orEmpty())
        }
    }
    fun buildBottom(isSimple: Boolean): CharSequence {
        val text = StringBuilder()
        if (!isSimple) {
            //阳男阴女顺排，阴男阳女逆排，一生一般排八步运
            //如庚戌年己卯月生男，为阳年生男。
            //其大运为：庚辰，辛巳，壬午，癸未，甲申，乙酉，丙戌，丁亥。
            //庚戌年己卯月生女，为阳年生女；
            //其大运为：戊寅，丁丑，丙子，乙亥，甲戌，癸酉，壬申，辛未。
            //丁酉年甲辰月生女，为阴年生女；
            //其大运为：乙巳，丙午，丁未，戊申，己酉，庚戌，辛亥，壬子。
            val ng = DataUtils.getTianGan(nianGanInfo?.name.orEmpty())
            val isBoy = sexType == 1
            val yy = ng.id % 2 == 1
            val aaa1 = DataUtils.getType(isBoy, yy)

            text.append("资讯:").append(aaa1).append("\n")
                .append("胎元：").append(taiYuan).append("(").append(DataUtils.getNaYinTu(taiYuan)).append(")  ")
                .append("命宫：").append(mingGong).append("(").append(DataUtils.getNaYinTu(mingGong)).append(")\n")
                .append("胎息：").append(taiXi).append("(").append(DataUtils.getNaYinTu(taiXi)).append(")  \n")
//        text.append("大运:").append(lucyYear.toString()).append("\n")
            lunar?.also {
                it.prevJieQi
                it.nextJieQi
                text.append("上节气:").append(it.prevJie.toText()).append("\n")
                text.append("下节气:").append(it.nextJie.toText()).append("\n")
            }

//            val aaa2 = DataUtils.getType(aaa1)
//            val preLunarTerm = Birth.getTargetLunarTerm(-1,time)
//            val nextLunarTerm = Birth.getTargetLunarTerm(1,time)
//            text.append("上节气:").append(preLunarTerm).append("\n")
//            text.append("下节气:").append(nextLunarTerm) .append("\n")
//            val term = if(aaa2)  nextLunarTerm else preLunarTerm
//            //小寒2024年1月6日4时50分，立春2024年2月4日16时27分
//            //起运周岁：5岁 10个月 22天，交运日期：12月15日(公历)
//            val offsetDay = term.offsetDay
//            //三、第三步：计算行运岁
//            //（1）（按三天计为一岁行大运，即一天计四个月行大运、一个时辰计十天行大运等之类。）
//            //（2）计算多少岁行运：
//            //公式：计算出的天数/3（得出结果）
////        var startYunYear = offsetDay / 3
////        var startYunMonth = (offsetDay % 3) * 4
//            //1）取整数：整数（不四舍五入）为岁；
//            //2）取整数后的余数天数：余数天数*4（取整数，结果为几个月）
//            //如：相差10天：计算后为10/3=3岁余1天；1天*4=4个月；
//            //最终结果为：3岁4个月开始行运
//            //（3）计算行运天数
//            //节令日当日的与命主的出生时辰相同的时辰与节令交季的时辰的差为时辰数
//            //序号
//            //即：
//            //1）节令所属时辰的序号—命主的出生时辰的序号的结果为相差的时辰数；
//            //2）时辰数*10=行运天数；
//            //3）判断：如果行运天数为负数，就在行运月数上直接—行运天数；
//            //如果行运天数为整数，就在行运月数上直接+行运天数；
//            //如：出生时辰为巳时，节令交际为酉时；则：（10-6）*10=40，为正数；
//            //则：其行运时间为：3岁4个月零40天
//            //若：出生时辰为酉时，节令交际为巳时；则：（6-10）*10=-40，为负数；
//            //则：其行运时间为：（在2岁4个月基础上减40天）3岁2个月零20天行运。
//            val teamModel = DataUtils.getTeamModel( String.format("%02d-%02d-%02d",term.year,term.month,term.day))
//            teamModel?.also {
//                val yunYear = offsetDay / 360
//                val yunMonth = (offsetDay % 360) / 30
//                val yunDay = offsetDay % 30
//                text.append("起运周岁:${yunYear}岁${yunMonth}个月${yunDay}天").append("\n")
//                LogUtils.d("teamModel: $it  offsetDay:$offsetDay yunYear:${yunYear}年${yunMonth}月${yunDay}日")
//            }
            lunar?.getEightChar()?.getYun(sexType)?.also {
                text.append("起运周岁:${it.startYear}岁${it.startMonth}个月${it.startDay}天").append("\n")
            }
            lunar?.apply {
                text.append(this.gong).append("方").append(this.shou)
                text.append("\t\t星宿[").append(this.xiu).append(this.zheng).append(this.animal).append("](")
                    .append(this.xiuLuck).append(")")
                text.append("\n彭祖百忌[").append(this.pengZuGan).append(" ").append(this.pengZuZhi).append("]");
                text.append("\n喜神方位[").append(this.dayPositionXi).append("](").append(this.dayPositionXiDesc)
                    .append(")")
                text.append("\n阳贵神方位[").append(this.dayPositionYangGui).append("](")
                    .append(this.dayPositionYangGuiDesc).append(")")
                text.append("\t\t阴贵神方位[").append(this.dayPositionYinGui).append("](")
                    .append(this.dayPositionYinGuiDesc).append(")")
                text.append("\n福神方位[").append(this.dayPositionFu).append("](").append(this.dayPositionFuDesc)
                    .append(")");
                text.append("\t\t财神方位[").append(this.dayPositionCai).append("](").append(this.dayPositionCaiDesc)
                    .append(")")
                text.append("\n冲[").append(this.dayChongDesc).append("]")
                text.append("\t\t煞[").append(this.daySha).append("]\n")
            }

            val tglineArr = mutableListOf(
                nianGanInfo?.name.orEmpty(), yueGanInfo?.name.orEmpty(), riGanInfo?.name.orEmpty
                    (), shiGanInfo?.name.orEmpty()
            )
            val dzlineArr = mutableListOf(
                nianZhiInfo?.name.orEmpty(), yueZhiInfo?.name.orEmpty(), riZhiInfo?.name.orEmpty
                    (), shiZhiInfo?.name.orEmpty()
            )
            var liuYi = Bazhi.getLiuYi(tglineArr, dzlineArr)
            text.append("八字天干留意:${liuYi[0]}").append("\n")
            text.append("八字地支留意:${liuYi[1]}").append("\n")

            val aa = DataUtils.getTianYiGuiRen(this)
            text.append("天乙贵人地支:${aa}").append("\n")
            text.append("天乙贵人留意:${DataUtils.getTianYiGuiRenLiuRi(this, aa)}").append("\n")

            appendGz(daYunGanInfo,tglineArr)
            appendGz(liuNianGanInfo,tglineArr)
            appendGz(liuYueGanInfo,tglineArr)
            appendGz(liuRiGanInfo,tglineArr)

            appendGz(daYunZhiInfo,dzlineArr)
            appendGz(liuNianZhiInfo,dzlineArr)
            appendGz(liuYueZhiInfo,dzlineArr)
            appendGz(liuRiZhiInfo,dzlineArr)

            liuYi = Bazhi.getLiuYi(tglineArr, dzlineArr)
            text.append("大运天干留意:${liuYi[0]}").append("\n")
            text.append("大运地支留意:${liuYi[1]}").append("\n")
            text.append("财库:${DataUtils.getCaiKu(this)}").append("\n")
            text.append("催财方位:${DataUtils.cuicaidili()}").append("\n")
            text.append("补印:${buYin()}").append("\n")
            text.append("地支十二论:${dizhiShierlunModel?.content}\n${dizhiShierlunModel?.desc}").append("\n")
        }
        return text
    }

    private fun buYin(): String {
        if (daYunIndex == -1 || liuNianIndex == -1) {
            return ""
        }
        var yunCoin = coin
        yun?.elementAtOrNull(daYunIndex + 1)?.also {
            val yunWx =
                if (liuNianIndex >= 5) {
                    val dizhi = DataUtils.getDiZhiInfo(it.ganZhi[1].toString())
                    dizhi.wuXing
                } else {
                    val tiangan = DataUtils.getTianGan(it.ganZhi[0].toString())
                    tiangan.wuXing
                }
            if (xiYongShen.contains(yunWx)) {
                yunCoin += 10;
            } else {
                yunCoin -= 10;
            }
            val liuNian = it.getLiuNian(10)?.elementAtOrNull(liuNianIndex)
            val liuNianGan = DataUtils.getTianGan(liuNian?.ganZhi?.get(0).toString())
            if (xiYongShen.contains(liuNianGan.wuXing)) {
                yunCoin += 10
            } else {
                yunCoin -= 10
            }
        }
        if (yunCoin > 52) {
            return "身强不能补印"
        }
        var yinCount = checkShiShenYin(
            mutableListOf(
                nianGanInfo?.shiShen.orEmpty(), yueGanInfo?.shiShen.orEmpty(),
                shiGanInfo?.shiShen.orEmpty(), daYunGanInfo?.shiShen.orEmpty()
            )
        )
        yinCount += checkShiShenYin(nianZhiInfo?.shiShenList ?: mutableListOf())
        yinCount += checkShiShenYin(yueZhiInfo?.shiShenList ?: mutableListOf())
        yinCount += checkShiShenYin(riZhiInfo?.shiShenList ?: mutableListOf())
        yinCount += checkShiShenYin(shiZhiInfo?.shiShenList ?: mutableListOf())
        yinCount += checkShiShenYin(daYunZhiInfo?.shiShenList ?: mutableListOf())
        if (yinCount > 3) {
            return "有${yinCount}个印,不能再补印"
        }
        val riGan = DataUtils.getTianGan(riGanInfo?.name.orEmpty())
        val wuXingInfo = DataUtils.getWuXingInfo(riGan.wuXing)
        //0 =生我 1=比我 2=克我 3=我生 4=我克
        val buWuXing = wuXingInfo.shengKe.elementAtOrNull(0).orEmpty()
        return DataUtils.getNengLiangBuChongFangShi(buWuXing)
    }

    private fun checkShiShenYin(list: MutableList<String>): Int {
        var count = 0
        list.forEach {
            if (it == "正印" || it == "偏印") {
                count++
            }
        }
        return count
    }

    var daYunIndex: Int = -1
    var liuNianIndex: Int = -1
    var liuYueIndex: Int = -1
    var liuRiIndex: Int = -1
    var lunar: Lunar? = null
    var yun: MutableList<EightChar.DaYun>? = null
    var liuNianMap = mutableMapOf<Int, MutableList<ITextItem>>()

    fun buildDaYunList(): MutableList<ITextItem> {
        val list = mutableListOf<ITextItem>()
        yun?.also {
            for (i in 1 until it.size) {
                val item = it[i]
                list.add(DaYunItem(item.startYear, item.startAge, item.ganZhi).initShiShen(riGanInfo?.name.orEmpty()))
            }
        }
        return list
    }

    private val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm")
    fun getLiuNian(daYunPos: Int): MutableList<ITextItem> {
        val list = mutableListOf<ITextItem>()
        if (liuNianMap.containsKey(daYunPos)) {
            liuNianMap[daYunPos]?.also {
                list.addAll(it)
            }
            return list
        }
        yun?.elementAtOrNull(daYunPos + 1)?.also { dy ->
            dy.getLiuNian(10).forEach {
                list.add(LiuNianItem(it.year, it.age, it.ganZhi).initShiShen(riGanInfo?.name.orEmpty()))
            }
        }
        liuNianMap[daYunPos] = list
        return list
    }

    private val jieQi = arrayOf(
        "立春",
        "惊蛰",
        "清明",
        "立夏",
        "芒种",
        "小暑",
        "立秋",
        "白露",
        "寒露",
        "立冬",
        "大雪",
        "小寒"
    )

    fun getLiuYue(): MutableList<ITextItem> {
        val list = mutableListOf<ITextItem>()
        yun?.elementAtOrNull(daYunIndex + 1)?.getLiuNian(10)?.elementAtOrNull(liuNianIndex)?.liuYue?.also { ll ->
            ll.forEach {
                list.add(LiuYueItem(it.liuNian.year, it.index + 1, jieQi[it.index], it.ganZhi).initShiShen(riGanInfo?.name.orEmpty()))
            }
            return list
        }
        return list
    }

    fun getLiuRi(): MutableList<ITextItem> {
        val list = mutableListOf<ITextItem>()
        val liuNian = liuNianMap[daYunIndex]?.elementAtOrNull(liuNianIndex) ?: return list
        //找到年份
        val year = (liuNian as LiuNianItem).year.toString()
        //找到月份
        val arr: LongArray = DataUtils.getLiuRiRange(year, jieQi[liuYueIndex])
        val calendar = Calendar.getInstance()
        calendar.timeInMillis = arr[0]
        do {
            Birth(calendar).also {
                it.horoscope(sdf.format(calendar.time))
                list.add(
                    LiuRIItem(
                        it.newYear,
                        it.newMonth,
                        it.newDay,
                        it.year, it.month, it.day,
                        it.getcD()
                    ).initShiShen(riGanInfo?.name.orEmpty())
                )
            }
            calendar.add(Calendar.DATE, 1)
        } while (calendar.timeInMillis < arr[1])
        return list
    }

    private fun getMaxCangGanLen(vararg zhiInfos: ZhiInfo): Int {
        var len = 0
        zhiInfos.forEach {
            len = max(len, it.shiShenList.size)
        }
        return len
    }

    class ShowItem(val type: Int, val text: String, val isLike: Boolean = false) {
        companion object {
            fun genTitle(title: String): ShowItem {
                return ShowItem(type = 1, text = title)
            }

            fun genGan(text: String): ShowItem {
                return ShowItem(type = 2, text = text)
            }

            fun genContent(text: String): ShowItem {
                return ShowItem(type = 3, text = text)
            }
        }
    }

    @SuppressLint("SimpleDateFormat")
    fun buildList(): MutableList<ShowItem> {
        val list = mutableListOf<ShowItem>()
        list.add(ShowItem.genTitle("时间"))
        list.add(ShowItem.genTitle("年柱"))
        list.add(ShowItem.genTitle("月柱"))
        list.add(ShowItem.genTitle("日柱"))
        list.add(ShowItem.genTitle("时柱"))
        list.add(ShowItem.genTitle("大运"))
        list.add(ShowItem.genTitle("流年"))
        list.add(ShowItem.genTitle("流月"))
        list.add(ShowItem.genTitle("流日"))

        list.add(ShowItem.genTitle("十神"))
        list.add(ShowItem.genGan(nianGanInfo?.shiShen ?: ""))
        list.add(ShowItem.genGan(yueGanInfo?.shiShen ?: ""))

        list.add(ShowItem.genContent(if (sexType == 1) "元男" else "元女"))
        list.add(ShowItem.genGan(shiGanInfo?.shiShen ?: ""))
        list.add(ShowItem.genGan(daYunGanInfo?.shiShen ?: ""))
        list.add(ShowItem.genGan(liuNianGanInfo?.shiShen ?: ""))
        list.add(ShowItem.genGan(liuYueGanInfo?.shiShen ?: ""))
        list.add(ShowItem.genGan(liuRiZhiInfo?.shiShen ?: ""))

        list.add(ShowItem.genTitle("天干"))
        list.add(ShowItem.genGan("${nianGanInfo?.getText()}"))
        list.add(ShowItem.genGan("${yueGanInfo?.getText()}"))
        list.add(ShowItem.genGan("${riGanInfo?.getText()}"))
        list.add(ShowItem.genGan("${shiGanInfo?.getText()}"))
        list.add(ShowItem.genGan("${daYunGanInfo?.getText()}"))
        list.add(ShowItem.genGan("${liuNianGanInfo?.getText()}"))
        list.add(ShowItem.genGan("${liuYueGanInfo?.getText()}"))
        list.add(ShowItem.genGan("${liuRiGanInfo?.getText()}"))

        list.add(ShowItem.genTitle("地支"))
        list.add(ShowItem.genGan("${nianZhiInfo?.getText()}"))
        list.add(ShowItem.genGan("${yueZhiInfo?.getText()}"))
        list.add(ShowItem.genGan("${riZhiInfo?.getText()}"))
        list.add(ShowItem.genGan("${shiZhiInfo?.getText()}"))
        list.add(ShowItem.genGan("${daYunZhiInfo?.getText()}"))
        list.add(ShowItem.genGan("${liuNianZhiInfo?.getText()}"))
        list.add(ShowItem.genGan("${liuYueZhiInfo?.getText()}"))
        list.add(ShowItem.genGan("${liuRiZhiInfo?.getText()}"))

        list.add(ShowItem.genTitle("藏干"))
        list.add(ShowItem.genContent("${nianZhiInfo?.cangGan}"))
        list.add(ShowItem.genContent("${yueZhiInfo?.cangGan}"))
        list.add(ShowItem.genContent("${riZhiInfo?.cangGan}"))
        list.add(ShowItem.genContent("${shiZhiInfo?.cangGan}"))
        list.add(ShowItem.genContent("${daYunZhiInfo?.cangGan}"))
        list.add(ShowItem.genContent("${liuNianZhiInfo?.cangGan}"))
        list.add(ShowItem.genContent("${liuYueZhiInfo?.cangGan}"))
        list.add(ShowItem.genContent("${liuRiZhiInfo?.cangGan}"))

        val maxLen = getMaxCangGanLen(nianZhiInfo!!, yueZhiInfo!!, riZhiInfo!!, shiZhiInfo!!)
        val canZhiLabel = arrayOf("藏干", "十神", "")
        for (i in 0 until maxLen) {
            list.add(ShowItem.genTitle(canZhiLabel[i]))
            list.add(ShowItem.genContent("${nianZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
            list.add(ShowItem.genContent("${yueZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
            list.add(ShowItem.genContent("${riZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
            list.add(ShowItem.genContent("${shiZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
            list.add(ShowItem.genContent("${daYunZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
            list.add(ShowItem.genContent("${liuNianZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
            list.add(ShowItem.genContent("${liuYueZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
            list.add(ShowItem.genContent("${liuRiZhiInfo?.shiShenList?.elementAtOrElse(i) { "" }}"))
        }
        list.add(ShowItem.genTitle("星运"))
        list.add(ShowItem.genContent("${nianZhiInfo?.xinYun}"))
        list.add(ShowItem.genContent("${yueZhiInfo?.xinYun}"))
        list.add(ShowItem.genContent("${riZhiInfo?.xinYun}"))
        list.add(ShowItem.genContent("${shiZhiInfo?.xinYun}"))
        list.add(ShowItem.genContent("${daYunZhiInfo?.xinYun}"))
        list.add(ShowItem.genContent("${liuNianZhiInfo?.xinYun}"))
        list.add(ShowItem.genContent("${liuYueZhiInfo?.xinYun}"))
        list.add(ShowItem.genContent("${liuRiZhiInfo?.xinYun}"))

        list.add(ShowItem.genTitle("自座"))
        list.add(ShowItem.genContent("${nianZhiInfo?.ziZuo}"))
        list.add(ShowItem.genContent("${yueZhiInfo?.ziZuo}"))
        list.add(ShowItem.genContent("${riZhiInfo?.ziZuo}"))
        list.add(ShowItem.genContent("${shiZhiInfo?.ziZuo}"))
        list.add(ShowItem.genContent("${daYunZhiInfo?.ziZuo}"))
        list.add(ShowItem.genContent("${liuNianZhiInfo?.ziZuo}"))
        list.add(ShowItem.genContent("${liuYueZhiInfo?.ziZuo}"))
        list.add(ShowItem.genContent("${liuRiZhiInfo?.ziZuo}"))


        list.add(ShowItem.genTitle("纳音"))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(nianGanInfo?.name, nianZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(yueGanInfo?.name, yueZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(riGanInfo?.name, riZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(shiGanInfo?.name, shiZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(daYunGanInfo?.name, daYunZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(liuNianGanInfo?.name, liuNianZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(liuYueGanInfo?.name, liuYueZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getNaYinTu(liuRiGanInfo?.name, liuRiZhiInfo?.name) ?: ""))

        list.add(ShowItem.genTitle("空亡"))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(nianGanInfo?.name, nianZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(yueGanInfo?.name, yueZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(riGanInfo?.name, riZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(shiGanInfo?.name, shiZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(daYunGanInfo?.name, daYunZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(liuNianGanInfo?.name, liuNianZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(liuYueGanInfo?.name, liuYueZhiInfo?.name) ?: ""))
        list.add(ShowItem.genContent(DataUtils.getLiuJiaKongWang(liuRiGanInfo?.name, liuRiZhiInfo?.name) ?: ""))

        list.add(ShowItem.genTitle("神煞"))
        list.add(ShowItem.genContent(getShensha(lunar?.yearInGanZhi.orEmpty())))
        list.add(ShowItem.genContent(getShensha(lunar?.monthInGanZhi.orEmpty())))
        list.add(ShowItem.genContent(getShensha(lunar?.dayInGanZhi.orEmpty(), type = 1)))
        list.add(ShowItem.genContent(getShensha(lunar?.timeInGanZhi.orEmpty(), type = 1)))

        list.add(ShowItem.genContent(getShensha("${daYunGanInfo?.name}${daYunZhiInfo?.name}")))
        list.add(ShowItem.genContent(getShensha("${liuNianGanInfo?.name}${liuNianZhiInfo?.name}")))
        list.add(ShowItem.genContent(getShensha("${liuYueGanInfo?.name}${liuYueZhiInfo?.name}")))
        list.add(ShowItem.genContent(getShensha("${liuRiZhiInfo?.name}${liuRiZhiInfo?.name}")))

        return list
    }

    fun getShensha(ganzhi: String, type: Int = 0): String {
        val nianGanShenSha = getNianGanShenSha(nianGanInfo?.name.orEmpty(), ganzhi)
        val nz = nianZhiInfo?.name.orEmpty()
        val rz = riZhiInfo?.name.orEmpty()
        val nzIndex = lunar?.getYearZhiIndex() ?: (EightChar.MONTH_ZHI.indexOf(nz) - 1)
        val rzIndex = lunar?.getDayZhiIndex() ?: (EightChar.MONTH_ZHI.indexOf(rz) - 1)
        val gan = ganzhi[0].toString()
        val zhi = ganzhi[1].toString()
        val nianZhiShenSha = getNianZhiShen(nianZhiInfo?.name.orEmpty(), zhi, nzIndex, sexType)
        val nianZhiOther = getNianZhiOther("${nianGanInfo?.name}${nianZhiInfo?.name}", zhi)
        val yuezhiShenSha = getYueZhiShenSha(yueZhiInfo?.name.orEmpty(), gan, zhi, type)
        val riGanShenSha = getRiGanShenSha(riGanInfo?.name.orEmpty(), ganzhi)
        val riZhiShenSha = getRiZhiShenSha(rz, zhi, rzIndex)
        val set = hashSetOf<String>()
        set.addAll(nianGanShenSha.split(" "))
        if (nianZhiOther.isNotEmpty()) {
            set.add(nianZhiOther)
        }
        set.addAll(nianZhiShenSha.split(" "))
        set.addAll(yuezhiShenSha.split(" "))
        set.addAll(riGanShenSha.split(" "))
        set.addAll(riZhiShenSha.split(" "))
        val builder = StringBuilder()
        for (s in set) {
            if (s.isNotEmpty()) {
                builder.append(s).append("\n")
            }
        }
        return builder.toString()
    }

    var nianGanInfo: GanInfo? = null
    var nianZhiInfo: ZhiInfo? = null

    var yueGanInfo: GanInfo? = null
    var yueZhiInfo: ZhiInfo? = null

    var riGanInfo: GanInfo? = null
    var riZhiInfo: ZhiInfo? = null

    var shiGanInfo: GanInfo? = null
    var shiZhiInfo: ZhiInfo? = null

    var daYunGanInfo: GanInfo? = null
    var daYunZhiInfo: ZhiInfo? = null

    var liuNianGanInfo: GanInfo? = null
    var liuNianZhiInfo: ZhiInfo? = null

    var liuYueGanInfo: GanInfo? = null
    var liuYueZhiInfo: ZhiInfo? = null

    var liuRiGanInfo: GanInfo? = null
    var liuRiZhiInfo: ZhiInfo? = null

    //得分
    var coin: Int = -1
    var coinType: CoinType = CoinType.PIAN_RUO

    // 喜用神
    var xiYongShen: String = ""

    var animalsYear: String = ""
    var taiYuan: String = ""
    var taiXi: String = ""
    var mingGong: String = ""

    var newDate: Date? = null
    var lunarDate: Date? = null

    // 当前测算的阳历时间戳
    var time: Long = 0

    //当前测试的阳历真太阳时时间戳
    var sumTime: Long = 0

    // 1 男 0 女
    var sexType: Int = 0

    var dizhiShierlunModel: DizhiShierlunModel? = null

    open class Date(var year: Int, var month: Int, var day: Int, var text: String = "")


    open class BaseInfo {
        var name: String? = null
        var wuXing: String? = null
        var shiShen: String? = null
        var id: Int = 0
        var isLike: Boolean? = null // 喜忌

        fun getText(): String {
            return "$name$wuXing${getLikeText()}"
        }

        private fun getLikeText(): String {
            if (isLike == null) {
                return ""
            }
            return if (isLike!!) "(喜)" else "(忌)"
        }
    }

    class GanInfo : BaseInfo()
    class ZhiInfo(var shiShenList: MutableList<String> = mutableListOf()) : BaseInfo() {
        var cangGan = ""
        var ziZuo = ""
        var xinYun = ""
    }
}